def solve(s, t):
    s_dict = {}
    t_dict = {}
    for c in s:
        if c in s_dict:
            s_dict[c] += 1
        else:
            s_dict[c] = 1

    for c in t:
        if c in t_dict:
            t_dict[c] += 1
        else:
            t_dict[c] = 1

    for k, v in s_dict.items():
        if k not in t_dict or v != t_dict[k]:
            return False

    for k, v in t_dict.items():
        if k not in s_dict or v != s_dict[k]:
            return False

    return True


if __name__ == "__main__":
    s = "anagram"
    t = "nagaram"
    print(solve(s, t))
